home *** CD-ROM | disk | FTP | other *** search
/ Mac OS 9 Serial Number Archive / SN Archive 2023.11.04.toast / BSNG / SDK / BSNG SDK 1.0.2 / BSNG Template / Template.c next >
Encoding:
C/C++ Source or Header  |  1997-10-08  |  9.2 KB  |  339 lines  |  [TEXT/CWIE]

  1. /*
  2.  * $Workfile:: Template.c                                                     $
  3.  * $Revision:: 2                                                              $
  4.  *
  5.  * $Author:: Buck Rogers                                                      $
  6.  * $Modtime:: 08.10.1997 02:02 Uhr                                            $
  7.  *
  8.  * $History:: Template.c                                                      $
  9.  * 
  10.  * *****************  Version 2  *****************
  11.  * User: Buck Rogers  Date: 08.10.1997   Time: 02:02 Uhr
  12.  * Updated in $/BSNG/Plugins/BSNG SDK/BSNG Template
  13.  * changed lf to cr in list generation so Mac compatible output is created
  14.  * 
  15.  * *****************  Version 1  *****************
  16.  * User: Buck Rogers  Date: 06.10.1997   Time: 06:25 Uhr
  17.  * Created in $/BSNG/Plugins/BSNG SDK/BSNG Template
  18.  * Adding subproject 'BSNG Template' to '$/BSNG/Plugins/BSNG SDK'
  19.  * 
  20.  * $NoKeywords::                                                              $
  21.  */
  22.  
  23.  
  24. #include <MixedMode.h>
  25. #include <A4Stuff.h>
  26.  
  27. #include "standard utils.h"
  28. #include "UltraU.h"
  29. #include "BSNG API.h"
  30.  
  31.  
  32. /*    don't touch this __procinfo definition or the calls from native code will crash the machine */
  33.  
  34. ProcInfoType __procinfo = kThinkCStackBased | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(BSNGParamBlockPtr)));
  35.  
  36.  
  37. /*    function prototypes for ANSI C */
  38.  
  39. static void DoInit(BSNGParamBlockPtr inData);
  40. static Boolean DoValidate(BSNGParamBlockPtr inData);
  41. static void DoCalc(BSNGParamBlockPtr inData);
  42. static void DoRandomCalc(BSNGParamBlockPtr inData);
  43. static Boolean DoAddRandomsToList(BSNGParamBlockPtr inData);
  44. static void DoItemHit(BSNGParamBlockPtr inData);
  45. static void DoCleanup(BSNGParamBlockPtr inData);
  46. void main(BSNGParamBlockPtr inData);
  47.  
  48.  
  49. /*    here is where the fun starts :-) */
  50.  
  51. static void DoInit(BSNGParamBlockPtr inData)
  52. {
  53.     StringPtr        item1 = inData->itemValue[kItemValue1];
  54.     StringPtr        item2 = inData->itemValue[kItemValue2];
  55.     StringPtr        item3 = inData->itemValue[kItemValue3];
  56.     StringPtr        item4 = inData->itemValue[kItemValue4];
  57.     StringPtr        item5 = inData->itemValue[kItemValue5];
  58.     StringPtr        item6 = inData->itemValue[kItemValue6];
  59.     StringPtr        item7 = inData->itemValue[kItemValue7];
  60.     StringPtr        item8 = inData->itemValue[kItemValue8];
  61.     StringPtr        item9 = inData->itemValue[kItemValue9];
  62.     StringPtr        item10 = inData->itemValue[kItemValue10];
  63.     
  64.     
  65.     /*    Initialize the Ultra Random Number generator (optional, use MacOS random functions otherwise) */
  66.     
  67.     Ultra_seed1 = inData->randSeed1;
  68.     Ultra_seed2 = inData->randSeed2;
  69.     Ultra_Init();
  70.     
  71.     /*    Give the BSNG App the informations if your plugin can do random calculations and if it can write
  72.         to the serial number list */
  73.     
  74.     inData->wantsRandomButton = true;
  75.     inData->canAddToSNList = true;
  76.     
  77.     /*    Initialize the EditFields with initial default values (optional, they are empty otherwise) */
  78.     /*    if you create a name-based generator please make sure that you copy the name, company and/or numCopies */
  79.     /*    values into the corrosponding fields */
  80.  
  81. /*    not name-based example
  82.     BlockMoveData("\p12345678", item1, 9);
  83.     BlockMoveData("\p23456789", item2, 9);
  84.     BlockMoveData("\p34567890", item3, 9);
  85.     item4[0] = 0;
  86. */
  87.  
  88.  
  89. /*    name-based example
  90.     BlockMoveData(inData->name, item1, inData->name[0] + 1);
  91.     BlockMoveData(inData->company, item2, inData->company[0] + 1);
  92.     BlockMoveData(inData->numCopies, item3, inData->numCopies[0] + 1);
  93.     item4[0] = 0;
  94. */
  95.  
  96.     /*    Tell the BSNG App if the initialisation was successful (it was in our case) */
  97.     
  98.     inData->error = errExtNoErr;
  99.     inData->errorInItem = 0;
  100. }  /* DoInit */
  101.  
  102.  
  103. static Boolean DoValidate(BSNGParamBlockPtr inData)
  104. {
  105.     StringPtr        item1 = inData->itemValue[kItemValue1];
  106.     StringPtr        item2 = inData->itemValue[kItemValue2];
  107.     StringPtr        item3 = inData->itemValue[kItemValue3];
  108.     StringPtr        item4 = inData->itemValue[kItemValue4];
  109.     StringPtr        item5 = inData->itemValue[kItemValue5];
  110.     StringPtr        item6 = inData->itemValue[kItemValue6];
  111.     StringPtr        item7 = inData->itemValue[kItemValue7];
  112.     StringPtr        item8 = inData->itemValue[kItemValue8];
  113.     StringPtr        item9 = inData->itemValue[kItemValue9];
  114.     StringPtr        item10 = inData->itemValue[kItemValue10];
  115.     Boolean            error = false;
  116.     
  117.     
  118.     /*    we do some simple checks here if the edit fields are not empty or not longer than 8 characters, additionally we could
  119.         also check if the values are really only numbers, but I skipped that because the input filter for the edit fileds
  120.         was set to integer anyway (defined in Constructor) */
  121.     
  122.     if ((item1[0] < 1) || (item1[0] > 8))
  123.     {
  124.         /*    if something was wrong in the input tell the BSNG App what edit field contained wrong values */
  125.         
  126.         inData->errorInItem = kEditItem1;
  127.         error = true;
  128.     }
  129.     else if ((item2[0] < 1) || (item2[0] > 8))
  130.     {
  131.         inData->errorInItem = kEditItem2;
  132.         error = true;
  133.     }
  134.     
  135.     if (error)
  136.     {
  137.         inData->error = errExtIncorrectValue;
  138.         return (false);
  139.     }
  140.     
  141.     inData->error = errExtNoErr;
  142.     
  143.     return (true);
  144. }  /* DoValidate */
  145.  
  146.  
  147. static void DoCalc(BSNGParamBlockPtr inData)
  148. {
  149.     StringPtr        item1 = inData->itemValue[kItemValue1];
  150.     StringPtr        item2 = inData->itemValue[kItemValue2];
  151.     StringPtr        item3 = inData->itemValue[kItemValue3];
  152.     StringPtr        item4 = inData->itemValue[kItemValue4];
  153.     StringPtr        item5 = inData->itemValue[kItemValue5];
  154.     StringPtr        item6 = inData->itemValue[kItemValue6];
  155.     StringPtr        item7 = inData->itemValue[kItemValue7];
  156.     StringPtr        item8 = inData->itemValue[kItemValue8];
  157.     StringPtr        item9 = inData->itemValue[kItemValue9];
  158.     StringPtr        item10 = inData->itemValue[kItemValue10];
  159.     
  160.     
  161.     /* do your calculations here */
  162.     
  163.     ZeroScrap();
  164. /*
  165.     PutScrap(result, 'TEXT', &(result[1]));
  166. */
  167. }  /* DoCalc */
  168.  
  169.  
  170. static void DoRandomCalc(BSNGParamBlockPtr inData)
  171. {
  172.     StringPtr        item1 = inData->itemValue[kItemValue1];
  173.     StringPtr        item2 = inData->itemValue[kItemValue2];
  174.     StringPtr        item3 = inData->itemValue[kItemValue3];
  175.     StringPtr        item4 = inData->itemValue[kItemValue4];
  176.     StringPtr        item5 = inData->itemValue[kItemValue5];
  177.     StringPtr        item6 = inData->itemValue[kItemValue6];
  178.     StringPtr        item7 = inData->itemValue[kItemValue7];
  179.     StringPtr        item8 = inData->itemValue[kItemValue8];
  180.     StringPtr        item9 = inData->itemValue[kItemValue9];
  181.     StringPtr        item10 = inData->itemValue[kItemValue10];
  182.     
  183.     
  184.     /*    prepare random calculations here */
  185.     
  186.     DoCalc(inData);
  187. }  /* DoRandomCalc */
  188.  
  189.  
  190. static Boolean DoAddRandomsToList(BSNGParamBlockPtr inData)
  191. {
  192.     StringPtr        item1 = inData->itemValue[kItemValue1];
  193.     StringPtr        item2 = inData->itemValue[kItemValue2];
  194.     StringPtr        item3 = inData->itemValue[kItemValue3];
  195.     StringPtr        item4 = inData->itemValue[kItemValue4];
  196.     StringPtr        item5 = inData->itemValue[kItemValue5];
  197.     StringPtr        item6 = inData->itemValue[kItemValue6];
  198.     StringPtr        item7 = inData->itemValue[kItemValue7];
  199.     StringPtr        item8 = inData->itemValue[kItemValue8];
  200.     StringPtr        item9 = inData->itemValue[kItemValue9];
  201.     StringPtr        item10 = inData->itemValue[kItemValue10];
  202.         
  203.     long            count = 0L;
  204.     short            i = 0;
  205.     OSErr            err = noErr;
  206.     
  207.     
  208.     /*    write your header to the number list */
  209.     
  210.     count = 24L;
  211.     err = FSWrite(inData->outputRefNum, &count, "<Your plugin name here>\r");
  212.     
  213.     /*    return false if an error occured, the creation of list will then be completly aborted */
  214.     
  215.     if (err != noErr)
  216.     {
  217.         return (false);
  218.     }
  219.     
  220.     count = 24L;
  221.     err = FSWrite(inData->outputRefNum, &count, "=======================\r");
  222.     
  223.     if (err != noErr)
  224.     {
  225.         return (false);
  226.     }
  227.     
  228.     /*    create numOfListNumbers random serial numbers and write them to the list */
  229.     /*    if you create a name-based generator please make sure that you create at least one number */
  230.     /*    using the name, company and/or numCopies informations. You could create more name-based numbers */
  231.     /*    by using your own name/company database */
  232.     
  233.     for (i = 0; i < inData->numOfListNumbers; i++)
  234.     {
  235.         DoRandomCalc(inData);
  236.         
  237.         /* write results to list here */
  238.     }
  239.     
  240.     /* don't forget this last newline */
  241.     
  242.     count = 1L;
  243.     err = FSWrite(inData->outputRefNum, &count, "\r");
  244.     
  245.     if (err != noErr)
  246.     {
  247.         return (false);
  248.     }
  249.     
  250.     return (true);
  251. }  /* DoAddRandomsToList */
  252.  
  253.  
  254. static void DoItemHit(BSNGParamBlockPtr inData)
  255. {
  256.     switch (inData->itemMessage)
  257.     {
  258.         case (300000):
  259.         
  260.             /*    the "About this plugin" button was pressed, do whatever you want, I just display a small Alert here */
  261.         
  262.             NoteAlert(1000, nil);
  263.             break;
  264.         
  265.         default:
  266.             break;
  267.     }
  268. }  /* DoItemHit */
  269.  
  270.  
  271. static void DoCleanup(BSNGParamBlockPtr inData)
  272. {
  273. #pragma unused (inData)
  274.  
  275.     /*    we didn't allocate any memory in DoInit, so we can leave this empty, otherwise it would be a VERY good idea
  276.         to deallocate/dispose etc. everything we allocated during our work. If you don't do that we have a nice memory leak */
  277.     
  278. }  /* DoCleanup */
  279.  
  280.  
  281. void main(BSNGParamBlockPtr inData)
  282. {
  283. #if (!GENERATINGPOWERPC)
  284.     EnterCodeResource();
  285. #endif
  286.     
  287.     /*    the message dispatcher */
  288.     
  289.     switch(inData->theMessage)
  290.     {
  291.         case (msgExtInit):
  292.             DoInit(inData);
  293.             break;
  294.         
  295.         case (msgExtCalcHit):
  296.         
  297.             if (DoValidate(inData))
  298.             {
  299.                 DoCalc(inData);
  300.             }
  301.             
  302.             break;
  303.         
  304.         case (msgExtRandomHit):
  305.             DoRandomCalc(inData);
  306.             break;
  307.         
  308.         case (msgExtCreateRandom):
  309.             
  310.             /*    report to the BSNG App if your list entry was written ok or if we had an error */
  311.             
  312.             if (DoAddRandomsToList(inData))
  313.             {
  314.                 inData->error = errExtNoErr;
  315.             }
  316.             else
  317.             {
  318.                 inData->error = errExtWritingToList;
  319.             }
  320.             
  321.             break;
  322.         
  323.         case (msgExtItemHit):
  324.             DoItemHit(inData);
  325.             break;
  326.         
  327.         case (msgExtCleanup):
  328.             DoCleanup(inData);
  329.             break;
  330.         
  331.         default:
  332.             break;
  333.     }
  334.     
  335. #if (!GENERATINGPOWERPC)
  336.     ExitCodeResource();
  337. #endif
  338. }  /* main */
  339.